﻿
(function () {
    var root = this;

    var loader = new function () { };
    if (typeof exports !== 'undefined') {
        if (typeof module !== 'undefined' && module.exports) {
            exports = module.exports = loader;
        }
        exports.loader = loader;
    } else {
        root['loader'] = loader;
    }

    loader.load = function (url, useCache) {

        var splitted = url.split('/');
        var name = '';
        _.each(splitted, function (split) { name += split.replace('.', '_'); });

        var item = null;
        if (useCache == true) item = $.jStorage.get(name);

        if (item == null) {
            var request = loader.getRequest();
            request.open("GET", url, false);
            request.send(null);
            item = request.responseText;
            if (useCache == true) $.jStorage.set(name, item)
        }

        return item;
    };


    loader.getRequest = function makeHttpObject() {
        try { return new XMLHttpRequest(); }
        catch (error) { }
        try { return new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (error) { }
        try { return new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (error) { }

        throw new Error("Could not create HTTP request object.");
    }


}).call(this);
